package com.bw;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.lionsoul.ip2region.DbConfig;
import org.lionsoul.ip2region.DbSearcher;


import java.util.HashMap;
import java.util.Map;


/**
 * @BelongsProject: ShiXun1_2211B
 * @BelongsPackage: com.bw
 * @Author: zhangleqing
 * @CreateTime: 2025-07-17  08:56
 * @Description: TODO
 * @Version: 1.0
 */
public class iptoregiom extends UDF{
    public Map<String, String> evaluate(String str) throws Exception{
        Map<String, String> map = new HashMap<>();

        DbSearcher dbSearcher = new DbSearcher(
                new DbConfig(),
                "/home/bwie/ip2region.db"
        );

        String region = dbSearcher.binarySearch(str).getRegion();

        // 国家、省份、城市、区域、网络供应商
        // 国家|省份|城市|区域|网络供应商

        String[] split = region.split("\\|");
        map.put("country", split[0]);
        map.put("area", split[1]);
        map.put("province", split[2]);
        map.put("city", split[3]);
        map.put("isp", split[4]);

        return map;
    }

    public static void main(String[] args) {

    }
}
